library(ggplot2)
## Attaching package: 'ggplot2'
## The following object(s) are masked _by_ '.GlobalEnv':
##
## scale_colour_discrete, scale_fill_discrete
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
library(reshape2) # for melt
crimesm <- melt(crimes, id = 1)
require(maps)
## Loading required package: maps
states_map <- map_data("state")
ggplot(crimes, aes(map_id = state)) + geom_map(aes(fill = Murder), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat)
last_plot() + coord_map()
ggplot(crimesm, aes(map_id = state)) + geom_map(aes(fill = value), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat) + facet_wrap(~variable)
These are the same plots with fig.show='hold' in the options
ggplot(crimes, aes(map_id = state)) + geom_map(aes(fill = Murder), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat)
last_plot() + coord_map()
ggplot(crimesm, aes(map_id = state)) + geom_map(aes(fill = value), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat) + facet_wrap(~variable)
Author: Jim Hester Created: 2013 Mar 28 02:44:48 PM Last Modified: 2013 Mar 28 03:18:18 PM